// 获取product
var oProduct = document.querySelector(".product");

var regExp = /(?<=imgurl=)[^'"]*/;
var xhr = new XMLHttpRequest();
xhr.open("get","http://chst.vip:1234/api/getinlanddiscount");
xhr.send();
xhr.onreadystatechange = function(){
    if(xhr.readyState === 4 && xhr.status === 200){
        var res = JSON.parse(xhr.responseText);
        console.log(res);
        var rex = res.result;
        var ele = ""
        rex.forEach(item => {
        ele += `
        <div class="shop" productId="${item.productId}">
   ${item.productImg}
   <span productId="${item.productId}">${item.productName}</span>
   <span productId="${item.productId}">${item.productPrice}</span>
   <span productId="${item.productId}">${item.productFrom}${item.productTime}</span>
</div>
        `
        });
        oProduct.innerHTML = ele;
    }
}
// 点击事件
oProduct.onclick = function(event){
    var e = event || window.event;
    var target = e.target || e.srcElement;
    console.log(target);
    var _this;
    if(target.nodeName != "img"){
         _this = target.parentNode;
    }else{
         _this = target;
    }
    var id = target.getAttribute("productId");
    console.log(id);
    location.href="../html/折扣详情.html?productid="+id;
}

$("gotop").click(function(){
    $("body,html").animate({scrollTop:0},2000)
})

